//! 地址生成器测试
//! 
//! 测试 src/generators/address.rs 中的地址生成功能

use dataforge::generators::address::*;

#[test]
fn test_us_state_generation() {
    for _ in 0..10 {
        let state = us_state();
        assert!(!state.is_empty());
        assert!(state.len() > 2);
        println!("美国州名: {}", state);
    }
}

#[test]
fn test_us_city_generation() {
    for _ in 0..10 {
        let city = us_city();
        assert!(!city.is_empty());
        assert!(city.len() > 2);
        println!("美国城市: {}", city);
    }
}

#[test]
fn test_zh_province_generation() {
    for _ in 0..10 {
        let province = zh_province();
        assert!(!province.is_empty());
        // 中国省份名称通常以"省"、"市"、"区"结尾
        assert!(province.ends_with("省") || province.ends_with("市") || 
                province.ends_with("区") || province.ends_with("自治区"));
        println!("中国省份: {}", province);
    }
}

#[test]
fn test_zh_city_generation() {
    for _ in 0..10 {
        let city = zh_city();
        assert!(!city.is_empty());
        println!("中国城市: {}", city);
    }
}

#[test]
fn test_zh_street_generation() {
    for _ in 0..10 {
        let street = zh_street();
        assert!(!street.is_empty());
        // 应该以街道后缀结尾
        assert!(street.ends_with("街") || street.ends_with("路") || 
                street.ends_with("大道") || street.ends_with("巷") || 
                street.ends_with("胡同") || street.ends_with("里"));
        println!("中国街道: {}", street);
    }
}

#[test]
fn test_us_address_complete() {
    for _ in 0..5 {
        let address = us_address();
        assert!(!address.is_empty());
        assert!(address.contains(",")); // 应该包含逗号分隔符
        assert!(address.chars().any(|c| c.is_ascii_digit())); // 应该包含数字
        println!("完整美国地址: {}", address);
    }
}

#[test]
fn test_zh_address_complete() {
    for _ in 0..5 {
        let address = zh_address();
        assert!(!address.is_empty());
        println!("完整中国地址: {}", address);
    }
}

#[test]
fn test_address_data_variety() {
    let mut us_states = std::collections::HashSet::new();
    let mut us_cities = std::collections::HashSet::new();
    let mut zh_provinces = std::collections::HashSet::new();
    let mut zh_cities = std::collections::HashSet::new();
    let mut zh_streets = std::collections::HashSet::new();
    
    for _ in 0..50 {
        us_states.insert(us_state());
        us_cities.insert(us_city());
        zh_provinces.insert(zh_province());
        zh_cities.insert(zh_city());
        zh_streets.insert(zh_street());
    }
    
    println!("生成了 {} 个不同的美国州名", us_states.len());
    println!("生成了 {} 个不同的美国城市", us_cities.len());
    println!("生成了 {} 个不同的中国省份", zh_provinces.len());
    println!("生成了 {} 个不同的中国城市", zh_cities.len());
    println!("生成了 {} 个不同的中国街道", zh_streets.len());
    
    // 应该有一定的多样性
    assert!(us_states.len() > 5);
    assert!(us_cities.len() > 10);
    assert!(zh_provinces.len() > 5);
    assert!(zh_cities.len() > 10);
    assert!(zh_streets.len() > 5);
}

#[test]
fn test_postal_code_generation() {
    for _ in 0..10 {
        let us_zip = us_postal_code();
        assert!(!us_zip.is_empty());
        assert!(us_zip.chars().all(|c| c.is_ascii_digit() || c == '-'));
        assert!(us_zip.len() >= 5); // 美国邮编至少5位
        println!("美国邮编: {}", us_zip);
        
        let zh_postal = zh_postal_code();
        assert!(!zh_postal.is_empty());
        assert!(zh_postal.chars().all(|c| c.is_ascii_digit()));
        assert_eq!(zh_postal.len(), 6); // 中国邮编6位
        println!("中国邮编: {}", zh_postal);
    }
}

#[test]
fn test_coordinate_generation() {
    for _ in 0..10 {
        let (lat, lng) = coordinate();
        
        // 纬度范围 -90 到 90
        assert!(lat >= -90.0 && lat <= 90.0);
        // 经度范围 -180 到 180
        assert!(lng >= -180.0 && lng <= 180.0);
        
        println!("坐标: ({:.6}, {:.6})", lat, lng);
    }
}

#[test]
fn test_china_coordinate_generation() {
    for _ in 0..10 {
        let (lat, lng) = china_coordinate();
        
        // 中国大陆的大致坐标范围
        assert!(lat >= 18.0 && lat <= 54.0); // 纬度
        assert!(lng >= 73.0 && lng <= 135.0); // 经度
        
        println!("中国坐标: ({:.6}, {:.6})", lat, lng);
    }
}